import { cargo } from "../base";


export interface CargoStatus {
    version: string,
    cy_left: boolean,
    cy_right: boolean,
    cy_top: boolean,
    cy_bottom: boolean,
    pick_origin: boolean,
    compr: boolean,
    cargo_btn: boolean,
    cargo_origin: boolean,
    loc2: boolean,
    pick_alm: boolean,
    cargo_alm: boolean,
}

interface PickCtrlReq {
    index: number,
    position: number,
}

export async function pickCtrl(req: PickCtrlReq) {
    await cargo.post('/pick_ctrl', req);
}

interface ComprCtrlReq {
    index: number,
    position: number,
}

export async function comprCtrl(req: ComprCtrlReq) {
    await cargo.post('/compr_ctrl', req);
}

export async function comprReset(index: number) {
    await comprCtrl({
        index,
        position: 1
    });
    await comprCtrl({
        index,
        position: 4,
    });
    await comprCtrl({
        index,
        position: 0,
    });
}

interface CargoCtrlReq {
    index: number,
    position: number,
}

export async function cargoCtrl(req: CargoCtrlReq) {
    await cargo.post('/cargo_ctrl', req);
}

export async function cargoScan(index: number) {
    let resp = await cargo.post('/scan', index);
    return resp.parse<string>();
}

interface CargoScanLedReq {
    index: number,
    ctrl: number,
}

export async function scanLedCtrl(req: CargoScanLedReq) {
    await cargo.post('/scan_led_ctrl', req);
}

interface RowColCtrlReq {
    index: number,
    row: number,
    col: number,
}

export async function rowColCtrl(req: RowColCtrlReq) {
    await cargo.post('/row_col_ctrl', req);
}

